#include <iostream>
#include <cstdio>

#define N 35

using namespace std;

const int dx[] = {0, -1, 1, 0, 0};
const int dy[] = {0, 0, 0, 1, -1};

int a[N][N];
int b[N][N];
int n;
const int optn = 2;

void dfs(int x, int y){
    if(y < 0 || y > n+1 || x < 0 || x > n+1 || a[x][y] != 0){
        return ;
    }
    a[x][y] = 1;
    for(int i = 1; i <= 4; i++){
        int xx = x + dx[i];
        int yy = y + dy[i];
        dfs(xx, yy);
    }
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            scanf("%d", &b[i][j]);
            if(b[i][j] == 0)    a[i][j] = 0;
            else a[i][j] = 2;
        }
    }
    dfs(0, 0);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(a[i][j] == 0)    printf("%d ", optn);
            else printf("%d ", b[i][j]);
        }
        printf("\n");
    }
    return 0;
}